package com.woniu.cms.contract.core.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.cms.contract.core.entity.FrameworkContract;
import com.woniu.cms.contract.core.service.IFrameworkContractService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author maple leaf
 * @since 2022-09-17
 */
@Api(tags = "框架合同")
@RestController
@RequestMapping("/framework-contract")
public class FrameworkContractController {

    @Autowired
    private IFrameworkContractService frameworkContractService;


    @ApiOperation("集审批 驳回编辑与一体")
    @PutMapping
    public Result updateFramework(@RequestBody FrameworkContract frameworkContract){
        Result result = frameworkContractService.addAuditFramework(frameworkContract);
        return result;
    }

    @ApiOperation("创建")
    @PostMapping
    public Result addFramework(@RequestBody FrameworkContract frameworkContract){
        Result result = frameworkContractService.addAuditFramework(frameworkContract);
        return result;
    }



    @ApiOperation("分页")
    @GetMapping
    public Result queryFramework(String frameworkContractCode, String clientName, Integer currentPage,Integer pageSize){

        Page<FrameworkContract> page = new Page<>(currentPage,pageSize);

        QueryWrapper<FrameworkContract> wrapper = new QueryWrapper<>();
        /* \u000d wrapper.eq("approval_result",2);*/

        if (frameworkContractCode != null && frameworkContractCode != ""){
            wrapper.like("framework_contract_code",frameworkContractCode);
        }
        if (clientName != null && clientName != ""){
            wrapper.like("client_name",clientName);
        }

        Page<FrameworkContract> frameworkContractPage = frameworkContractService.page(page, wrapper);

        List<FrameworkContract> records = frameworkContractPage.getRecords();

        long total = frameworkContractPage.getTotal();

        HashMap<String, Object> map = new HashMap<>();

        map.put("records",records);
        map.put("total",total);
        return Result.common(map);
    }


    @ApiOperation("编辑查询")
    @GetMapping("{frameworkContractCode}")
    public Result queryFramework(String frameworkContractCode){
        Result result = frameworkContractService.queryFramework(frameworkContractCode);
        return result;
    }


    @ApiOperation("删除合同")
    @DeleteMapping
    public Result deleFramework(String frameworkContractCode){
        Result result = frameworkContractService.deleFramework(frameworkContractCode);
        return result;
    }



}

